﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Preprocess;
using utility;
namespace test
{
    public partial class Form1 : Form
    {
        List<Rectangle> rect = new List<Rectangle>();
        public Form1()
        {
            PictureBox pic = new PictureBox();
            
            InitializeComponent();
            using (FileStream file = new FileStream("rect.bin", FileMode.Open))
            {
                BinaryFormatter bin = new BinaryFormatter();
                rect = (List<Rectangle>)bin.Deserialize(file);
                List<Bitmap> bms = new List<Bitmap>();
                Pen borderPen = new Pen(Color.FromArgb(150, 0, 255, 0));
                Bitmap bm1 = new Bitmap("s.JPG");
                Bitmap bm = bm1.Clone(new Rectangle(0, 0, bm1.Width, bm1.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Process.inVerse(ref bm);
                Graphics g = Graphics.FromImage(bm);
                pictureBox1.Width = bm.Width;
                pictureBox1.Height = bm.Height;
                
                this.Width = bm.Width + 1;
                this.Height = bm.Height + 1;
                List<Bitmap> lbm = new List<Bitmap>();
                List<double[,]> listpattern = new List<double[,]>();
                for (int i = 0; i < rect.Count; i++)
                {
                    
                    bms.Add(bm.Clone(rect[i], System.Drawing.Imaging.PixelFormat.Format24bppRgb));
                    //bms[i].SetResolution(bms[i].HorizontalResolution, bms[i].VerticalResolution);
                    Process.fixedSizeImage(bms[i]).Save(i.ToString("0") + " .JPG");
                    g.DrawRectangle(borderPen, rect[i]);
                   listpattern.Add(tools.GDIBitmapToMatrix(Process.fixedSizeImage(bms[i])));
                    lbm.Add(tools.MatrixToEquavalentImage(listpattern[i]));
                    
                    
                   lbm[i].Save(i.ToString("00") + ".JPG");
                    
                }
                pictureBox1.Image = bm;
            }
        }

    }
}
